package cn.ycc1.baseset.classes;

/**
 * When to Use Nested Classes, Local Classes, Anonymous Classes, and Lambda Expressions
 * @author ycc
 * @date 2025/3/4
 * Choosing Between Nested Classes, Local Classes, Anonymous Classes, and Lambda Expressions
 * As mentioned in the section Nested Classes, nested classes enable you to logically group classes that are only used
 * in one place, increase the use of encapsulation, and create more readable and maintainable code. Local classes,
 * anonymous classes, and lambda expressions also impart these advantages; however, they are intended to be used for
 * more specific situations:
 *
 * Local class: Use it if you need to create more than one instance of a class, access its constructor, or introduce a new,
 * named type (because, for example, you need to invoke additional methods later).
 * Anonymous class: Use it if you need to declare fields or additional methods.
 * Lambda expression:
 * Use it if you are encapsulating a single unit of behavior that you want to pass to other code. For example,
 * you would use a lambda expression if you want a certain action performed on each element of a collection,
 * when a process is completed, or when a process encounters an error.
 * Use it if you need a simple instance of a functional interface and none of the preceding criteria apply (for example,
 * you do not need a constructor, a named type, fields, or additional methods).
 * Nested class: Use it if your requirements are similar to those of a local class, you want to make the type more widely
 * available, and you don't require access to local variables or method parameters.
 * Use a non-static nested class (or inner class) if you require access to an enclosing instance's non-public fields and
 * methods. Use a static nested class if you don't require this access.
 *
 * 正如嵌套类一节所述，嵌套类使您能够对仅在一个地方使用的类进行逻辑分组，增加封装的使用，并创建更可读和可维护的代码。
 * 本地类、匿名类和lambda表达式也具有这些优点；然而，它们旨在用于更具体的情况：
 *
 * 本地类：如果需要创建类的多个实例、访问其构造函数或引入新的命名类型（例如，因为稍后需要调用其他方法），请使用它。
 * 匿名类：如果需要声明字段或其他方法，请使用它。
 * Lambda表达式：
 * 如果要封装要传递给其他代码的单个行为单元，请使用它。例如，如果您希望在进程完成或遇到错误时对集合的每个元素执行特定操作，则可以使用lambda表达式。
 * 如果您需要一个函数接口的简单实例，并且上述条件都不适用（例如，您不需要构造函数、命名类型、字段或其他方法），请使用它。
 * 嵌套类：如果您的要求与局部类的要求相似，您希望使类型更广泛地可用，并且不需要访问局部变量或方法参数，请使用它。
 * 如果需要访问封闭实例的非公共字段和方法，请使用非静态嵌套类（或内部类）。如果不需要此访问权限，请使用静态嵌套类。
 */
public class WhenToUse {
}
